package com.mfin.bs.mappers.impl;

import com.mfin.bom.interfaces.ICustomer;
import com.mfin.bom.interfaces.IUser;
import com.mfin.enumeration.UserRole;
import com.mfin.vo.CustomerVO;
import com.mfin.vo.UserVO;
import com.mfin.vo.interfaces.IMappable;

public class UserMapper extends BaseMapper {

	@Override
	protected boolean doMap(IMappable fromArg, IMappable toArg) {
		boolean canPerformMap = false;

		if (fromArg instanceof IUser && toArg instanceof UserVO) {
			canPerformMap = true;
			performMap((IUser) fromArg, (UserVO) toArg);
		} else if (fromArg instanceof CustomerVO && toArg instanceof ICustomer) {
			performMap((UserVO) fromArg, (IUser) toArg);
			canPerformMap = true;
		}
		return canPerformMap;
	}

	private void performMap(UserVO fromArg, IUser toArg) {
		if (fromArg.getUserId() != null) {
			toArg.setUserId(fromArg.getUserId());
		}
		toArg.setPassword(fromArg.getPassword());
		toArg.setRole(UserRole.USER);
	}

	private void performMap(IUser fromArg, UserVO toArg) {
		toArg.setUserId(fromArg.getUserId());
		toArg.setPassword(fromArg.getPassword());
		toArg.setRole(UserRole.USER);
	}
}
